/*
 * @Author: Suo-Yuheng syh15399227325@163.com
 * @Date: 2025-08-24 19:16:20
 * @LastEditors: Suo-Yuheng syh15399227325@163.com
 * @LastEditTime: 2025-08-24 20:33:39
 * @FilePath: /0824/mkfifo_/comm.hpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#pragma once
#include<iostream>
#include<sys/types.h>
#include<sys/stat.h>
#include<cerrno>
#include<cstring>
#include<cstdlib>
#include<unistd.h>
#include<fcntl.h>
#include<string>

#include"log.hpp"

#define FIFO_FILE "./myfifo"
#define MODE 0664

enum{
    FIFO_CREATE_ERR = 1,
    FIFO_DELETE_ERR,
    FIFO_OPEN_ERR,
};

class Init
{
public:
    Init()
    {
        // 创建信道 —— 命名管道
        int n = mkfifo(FIFO_FILE, MODE);
        if(n == -1)
        {
            // printf("%d: %s\n", errno, strerror(errno));
            perror("mkfifo");
            exit(FIFO_CREATE_ERR);
        }
    }

    ~Init()
    {
        int m = unlink(FIFO_FILE);
        if(m == -1)
        {
            perror("unlink");
            exit(FIFO_DELETE_ERR);
        }
    }
};